<template>
	<div class="content">
		<Collapse v-model="value1">
			<Panel name="1">
				V1
				<p slot="content">
					<Form label-position="right" :label-width="100">
						<div class="canshu" v-for="(item,index) of config.v1" :key="index">
							<FormItem :label="index == 0 ? '规则：':''">
								直推荐
								<Input class="w80" v-model="item.startNum" /><span v-show="index == config.v1.length - 1"> - <Input class="w80" v-model="item.endNum" /></span>名有效用户可拿
								<Input class="w80" v-model="item.startLay" /><span v-show="index == config.v1.length - 1"> - <Input class="w80" v-model="item.endLay" /></span>代存币理财收益的
								<Input class="w80" v-model="item.ratio" />%
								<Button style="margin-left: 15px;" type="primary" size="large" @click="updateRatios(item,index)">保　存</Button>
							</FormItem>
						</div>
					</Form>
				</p>
			</Panel>
			<Panel name="2">
				V2
				<p slot="content">
					<Form label-position="right" :label-width="100">
						<div class="canshu" v-for="(item,index) of config.v2" :key="index">
							<FormItem :label="index == 0 ? '规则：':''">
								直推荐
								<Input class="w80" v-model="item.startNum" /><span v-show="index == config.v2.length - 1"> - <Input class="w80" v-model="item.endNum" /></span>名有效用户可拿
								<Input class="w80" v-model="item.startLay" /><span v-show="index == config.v2.length - 1"> - <Input class="w80" v-model="item.endLay" /></span>代存币理财收益的
								<Input class="w80" v-model="item.ratio" />%
								<Button style="margin-left: 15px;" type="primary" size="large" @click="updateRatios(item,index)">保　存</Button>
							</FormItem>
						</div>
					</Form>
				</p>
			</Panel>
			<Panel name="3">
				V3
				<p slot="content">
					<Form label-position="right" :label-width="100">
						<div class="canshu" v-for="(item,index) of config.v3" :key="index">
							<FormItem :label="index == 0 ? '规则：':''">
								直推荐
								<Input class="w80" v-model="index == config.v3.length - 1 ? Number(config.v3[index - 1].endNum).add(1) : item.startNum" :disabled="index == config.v3.length - 1" /><span v-if="index == config.v3.length - 2"> - <Input class="w80" v-model="item.endNum" /></span>名<span v-if="index == config.v3.length - 1">以上</span>有效用户可拿
								<Input class="w80" v-model="index == config.v3.length - 1 ? Number(config.v3[index - 1].endLay).add(1) : item.startLay" :disabled="index == config.v3.length - 1" /><span v-show="index == config.v3.length - 1 || index == config.v3.length - 2" :disabled="index == config.v3.length - 1"> - <Input class="w80" v-model="item.endLay"  :disabled="index == config.v3.length - 1"  /></span>代存币理财收益的
								<Input class="w80" v-model="item.ratio" />%
								<Button style="margin-left: 15px;" type="primary" size="large" @click="updateRatios(item,index)">保　存</Button>
							</FormItem>
						</div>
					</Form>
				</p>
			</Panel>
		</Collapse>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				value1: [1, 2, 3], // 默认展开第一个列表
				config: [],
				dataValue: '',
				token: localStorage.mytoken,
				minPool: '',
			}
		},
		created() {

		},
		mounted() {
			this.$Message.config({
				top: 250
			});
			this.getOther(); // 其他配置查询
		},
		methods: {
			updateRatios(item, i) {
				//根据ID判断是新增还是修改
				this.axios.post('/admin/push/config/update', this.qs.stringify({
					id: item.id,
					levelId: item.levelId,
					startNum: item.startNum,
					startLay: item.startLay,
					endNum: item.endNum,
					endLay: item.endLay,
					ratio: item.ratio,
				})).then(res => {
					if(res.data.code == 200) {
						this.$Message.info(res.data.msg);
					}
				})
				if(item.levelId == 3 && i == 2) {
					i++;
					this.axios.post('/admin/push/config/update', this.qs.stringify({
						id: this.config.v3[i].id,
						levelId: this.config.v3[i].levelId,
						startNum: Number(this.config.v3[i - 1].endNum).add(1),
						startLay: Number(this.config.v3[i - 1].endLay).add(1),
						endNum: this.config.v3[i].endNum,
						endLay: this.config.v3[i].endLay,
						ratio: this.config.v3[i].ratio,
					})).then()
				}
			},
			getOther() {
				this.axios.get('/admin/push/config/get').then(res => {
					if(res.data.code == 200) {
						this.config = res.data.data;
						this.config.v1.forEach((item, i) => {
							this.config.v1[i].ratio = Number(item.ratio).mul(100);
						})
						this.config.v2.forEach((item, i) => {
							this.config.v2[i].ratio = Number(item.ratio).mul(100);
						})
						this.config.v3.forEach((item, i) => {
							this.config.v3[i].ratio = Number(item.ratio).mul(100);
						})
					}
				})
			},
		}
	}
</script>

<style lang="less" scoped>
	.p-10 {
		padding-top: 0 !important;
		padding-left: 50px !important;
	}
	
	.w50 {
		width: 50px !important;
	}
	
	.w25 {
		width: 25px !important;
	}
	
	.w120 {
		width: 120px !important;
	}
	
	.mar {
		margin-left: 5px;
	}
	
	.pl-100 {
		padding-left: 100px;
	}
	
	.visibility {
		visibility: hidden;
	}
</style>